//
//  UIImage+Additions.m
//
//  Created by Esther on 2016/12/10.
//  Copyright © 2016年 Esther. All rights reserved.
//


#import "UIImage+Additions.h"

@implementation UIImage (Additions)

#pragma mark -
#pragma mark - 图片剪裁圆形不带边框
+ (UIImage *)ss_image:(UIImage *)image{
    UIGraphicsBeginImageContextWithOptions(image.size, NO, 0);
    //绘制剪裁
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, image.size.width, image.size.width)];
    
    [path addClip];
    
    //绘制到上下文
    [image drawAtPoint:CGPointZero];
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    //关闭
    UIGraphicsEndImageContext();
    
    return newImage;
    
}

#pragma mark -
#pragma mark - 图片剪裁圆形带边框
+ (UIImage *)ss_imageWithBorder:(CGFloat )borderW borderColor:(UIColor *)borderColor image:(UIImage *)image{
    //开启上下文
    CGSize size = CGSizeMake(image.size.width + 2 * borderW, image.size.height + 2 * borderW);
    UIGraphicsBeginImageContextWithOptions(size, NO, 0);
    //绘制
    UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
    
    [borderColor set];
    [path fill];
    
    //绘制中间圆
    UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(borderW, borderW, image.size.width, image.size.height)];
    [clipPath addClip];
    //将图片加入上下文
    [image drawAtPoint:CGPointMake(borderW, borderW)];
    
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    return newImage;
    
}

#pragma mark -
#pragma mark - 图片原始(不渲染)
+ (UIImage *)ss_imageWithImageName:(NSString *)imageName{
    return [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

@end
